Array of Skip lists

In continuation of thread posted before as below:

"To find whether an attributeValue of 1 module exists in another module
Posted: Sep 12, 2012 02:14:23 AM"

If the there are n number of modules to be checked(n will be known only at runtime), for a particular attribute value exists or not. What will be the approach. Can we use array of skipLists. I tried to put something like below. but it is giving error. How the array of skipList initialized when the number of skiplist to be generated is unknown.

Skip S_attValueListMod[]={}
for(ii=0;ii<selModCount;ii++){// for all selected Module

A_ad = find(selModii,attr)
if(!null ad){
for O_obj in selModii do {// error at this place as "array bounds exceeded(0)
S_attValueListModii = create()
if (isDeleted O_obj){continue}
if (table O_obj){continue}
if (row O_obj){continue}
eValue = O_obj.attr
if (eValue == "") {continue}
if(find(S_attValueListModii, eValue, existIValue)) {
delete(S_attValueListModii, eValue)
put(S_attValueListModii, eValue, (++existIValue)) }
else{
put(S_attValueListModii, eValue, 1)
//print eValue "\n" } }
}
Thanks in Advance
PJAnurag - Fri Sep 21 06:26:06 EDT 2012

Re: Array of Skip lists
Mathias Mamsch - Fri Sep 21 07:54:02 EDT 2012

The good thing about an Array is, that it will resize itself. Not those one dimensional arrays like string[10] but the Array data type of DOORS. So you can declare an array with capacity (10,10) and then put 20x20 items in there. Note that the Array does not track how many or which items are in there, you need to store these informations yourself in some variable.

But since you probably need to find the values for a specific module, you can use a Skip of Skips instead of an Array of Skips. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Array of Skip lists
Peter_Albert - Fri Sep 21 08:09:53 EDT 2012

Some thoughts and recommendations:

1) When you post code, put {c o d e} (without the empty spaces) around the actual code. Makes it looks nicer in the post, with indentation preserved, and also keeps the angular brackets (which are otherwise removed, making the part in between a hyperlink)

2) Turn autodeclare off, and explicitly declare variables. Otherwise you will spend hours debugging and in the end it is just a typo in a variable name.

3) In-line with the above, you should specify

string eValue
eValue = O_obj.attr ""

(Note the "" after the 'O_obj.attr' to force the result being a string. Honestly, I don't know what happens in your case. If the attribute 'attr' is of type integer, then eValue would be of the same type (I guess). Sometime later, when you loop through the Skip lists and have to retrieve the key, you will not know which type to cast and will be in trouble. Safer to stick to strings (letting aside the famous string table, but that's a different story)

4) If you follow 3) you must define the Skip lists with createString()

5) Array of Skip lists: would work, but (I think) you have to know the number of entries in advance. Which in fact you know, as you use 'selModCount'. The general structure for an array of Skip lists would be

int n = 2
Skip s[n] = {}
s[0] = createString()
put(s[0], "a", "a")
put(s[0], "b", "b")
s[1] = createString()
put(s[1], "a", "c")
put(s[1], "b", "d")
// ...
 
int i
Skip t
for i in 0:n-1 do
{
  t = s[i]
  string x
  for x in t do print x " "
  delete t // Don't forget to delete the Skip list to avoid memory leaks
}

6) If the number of elements is really unknown, I personally prefer Skip lists of Skip lists:

 

Skip sOuter = create()
int n = 0 
Skip sInner = null
 
sInner = createString()
put(sInner, "a", "a")
put(sInner, "b", "b")
put(sOuter, n++, sInner)
 
sInner = createString()
put(sInner, "a", "c")
put(sInner, "b", "d")
put(sOuter, n++, sInner)
 
// ...
 
int i
for i in 0:n-1 do
{
  if (find(sOuter,i, sInner))
  {
    string x
    for x in sInner do print x " "
    delete sInner // Don't forget to delete the Skip list to avoid memory leaks
  }
}
delete sOuter // don't forget to delete the "outer" SKip list as well

7) You don't have to "delete(S_attValueListMod ...; put(S_attValueListMod ...". Since v9.3, the "put" perm has a boolean flag which which you can overwrite entries:

 

put(S_attValueListMod,eValue,++existIValue,true)

Regards,

Peter

 

Re: Array of Skip lists
PJAnurag - Thu Sep 27 09:03:15 EDT 2012

thanks for the reply,
I have implemented skip of skips as per the instructions.But the error
"key used outside SkipList do loop" is occuring. I have attached my code. unable to solve the problem.

Is there any way to traverse through the skiplist like in array A[1], A[2]...

Thanks & Regards,
Anurag
Attachments

attachment_14891502_New1.dxl

Re: Array of Skip lists
llandale - Thu Sep 27 14:09:23 EDT 2012

PJAnurag - Thu Sep 27 09:03:15 EDT 2012
thanks for the reply,
I have implemented skip of skips as per the instructions.But the error
"key used outside SkipList do loop" is occuring. I have attached my code. unable to solve the problem.

Is there any way to traverse through the skiplist like in array A[1], A[2]...

Thanks & Regards,
Anurag

I've not followed this thread and am looking ONLY at your code. "new.dxl"

I see at line 53 you loop through your sInner skip and line 55 you use the "key" command correctly. But I see at line 60 you are modifying variable "sInner" within the loop starting at line 53. That's like doing this:
  • for i in 0:20 do
  • { for i in 0:10 do

I'm not following this well but suspect that at lines 50/53/55 you need to use a different Skip variable, perhaps "sOuter". That would make sense if the Skip stored at location 0 was some form of index into the Skips that start at location 1.

Deleting sInner at line 80 looks REAL bad; even if you were to 1st remove the skip from the Array first.

I notice you fail to declare "sInner". Gives me Heebee Jeebees.

-Louie

Re: Array of Skip lists
Peter_Albert - Fri Sep 28 03:46:33 EDT 2012

PJAnurag - Thu Sep 27 09:03:15 EDT 2012
thanks for the reply,
I have implemented skip of skips as per the instructions.But the error
"key used outside SkipList do loop" is occuring. I have attached my code. unable to solve the problem.

Is there any way to traverse through the skiplist like in array A[1], A[2]...

Thanks & Regards,
Anurag

Looking at your code I guess you want to look whether an attribute value of the fist Module appears in any of the other Modules. The code for doing that would look like the following (note that I couldn't check if it really runs without DXL errors, as you must have defined and populated somewhere above

void refreshSkipAttrList(){}
int  selModCountModule selMod[]
Skip   S_attValueListMod
DBE    lstDspAttr

Now the actual code would be

/*-------------------------------- **** --------------------------------
frequency 
-------------------------------- **** -------------------------------- */
void frequency(string attr) {  
  int     ii 
  string  eValue
  int     existIValue
  int     ReqCount=0
  Object  O_obj
  AttrDef A_ad
  Skip    sInner
  bool    acr
  acr = true
  refreshSkipAttrList()
  
  for(ii=0;ii<selModCount;ii++) //calculation for number of Modules
  {// for all selected Module
    ReqCount = 0
    A_ad = find(selMod[ii],attr)
    if(!null A_ad)
    {               
      sInner = createString()              
      for O_obj in selMod[ii] do { //calcualte the count of attribute values for attribute in each module                   
        ReqCount++
        if (!canRead(O_obj)) 
        { 
          acr = false
          continue 
        }
        if (isDeleted O_obj){continue}
        if (table     O_obj){continue}
        if (row       O_obj){continue}
        
        eValue = O_obj.attr""
        if (eValue == "")   {continue} 
        if(find(sInner, eValue, existIValue)) {++existIValue}
        else                                  {existIValue = 1}
        put(sInner, eValue,existIValue,true) 
      }
    }                      
    put(sInner, "Total_" name selMod[ii], ReqCount)
    put(S_attValueListMod,ii,sInner)
    
  }
  
  
  empty lstDspAttr
  int    ind, index = 0
  
  // Below is an example for simply looping over all Skip lists:
  /*
  for sInner in S_attValueListMod do
  {
    ind = (int key S_attValueListMod)
    print "\n" (name selMod[ind]) ": " 
    for existIValue in sInner do
    {
      eValue = (string key sInner)
      print "\n\t" eValue ": " existIValue ""
    }
  }
  */
  
  // From your code I guess you want to raise a flag when a given attribute
  // value from the first Module appears in any of the other Modules, if that's
  // the case, then you would do the following. Note that you need another 
  // Skip list which contains the respective values from the first Module
  
  Skip sFirstModule
  if (find(S_attValueListMod,0,sFirstModule))
  {
    string sAttValue
    int    iValue
    for iValue in sFirstModule do
    {
      sAttValue = (string key sFirstModule)
      // Now look for that attribute value in the other Skip lists
      flag = false
      for sInner in S_attValueListMod do
      {
        ind = (int key S_attValueListMod)
        if (ind == 0){continue} // Skip the first Module
        if (find(sInner, sAttValue)){flag = true}
        else {flag = false; break} // Do you really want to break here?
                                   // not found in second Module == no search in other Modules
      }
      if(flag)
      {
        insert(lstDspAttr,index++,sAttValue,iconNone)
      }
    }
  }
  // Delete all Skip lists
  for sInner in S_attValueListMod do {delete sInner}
  delete S_attValueListMod
} /* frequency */

As Louie already pointed out, your initial mistake was that you first used 'sInner' to contain the attribute values from the first Module (Line 53), then looped through 'sInner' (Line 56), but in that loop used the same variable name to assign it to each Skip list in 'S_attValueListMod' (Line 62). If you want to compare all Modules to the first, you have to reserve one additional Skip list, 'sFirstModule' in the code above.

An additonal comment: You had the 'break' command (Line 74) when an attribute value was not found in the other Modules. Is that what you want? If the attribute value is not found in the second Module, then you stop searching.

Regards,

Peter

 

Re: Array of Skip lists
PJAnurag - Fri Sep 28 03:48:28 EDT 2012

Thanks for the response.

Re: Array of Skip lists
Peter_Albert - Fri Sep 28 04:49:04 EDT 2012

PJAnurag - Fri Sep 28 03:48:28 EDT 2012
Thanks for the response.

From your other post here http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14891843 I now understand that you want to calculate the frequency of occurence of any attribute value over all selected Modules. This means that there still is a fundamental mistake in your approach: you are only reporting on attribute values which occur in the first Module and in any other Module (the second Module, actually, due to the "break" command).

You don't report on attribute values which only occur in Modules other than the first one, neither on attribute values which occur only once.

I'd recommend something like this instead:

Skip sAllAttrValues = createString
  for sInner in S_attValueListMod do
  {
    ind = (int key S_attValueListMod)
    for existIValue in sInner do
    {
      eValue = (string key sInner)
      put(sAllAttrValues, eValue , eValue) // This gives you a list
                                           // of all attribute values
                                           // in any of the Modules
    }
  }
  string sAttValue
  for sAttValue in sAllAttrValues do {
    insert(lstDspAttr,index++,sAttValue,iconNone)
  }

 


Much simpler, as you seem to be interested only in all values occuring anywhere.
If you need to know how often and in which Module, then you have to loop through sAllAttrValues, and in that loop through attValueListMod and fetch the matching pairs. Btu you have all examples at hand now to do this.

Regards,

Peter